package Common;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Calendar;


public class Log {

	private Writer _writer = null;
	
	/*Constructor for log class
	 * @fileName log file name which this log will log text to
	 */
	public Log(String fileName)
	{
		fileName = fileName + ".log";
		try {
		    _writer = new BufferedWriter(new FileWriter(fileName,false));  
		    
		} 
		catch (IOException ex) 
		{
		} 
	}
	
	
	/*function to log general information
	 * @procedure function name of the callee
	 * @msg message to save to log
	 */
	public void LogInof(String procedure,String msg)
	{
		
		String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
		String result = String.format("%s-Info-%s-%s", timeStamp,procedure,msg);
		try {
			_writer.write(result);
			_writer.write("/n");
			_writer.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/*function to log error information
	 * @procedure function name of the callee
	 * @msg message to save to log
	 */
	public void LogError(String procedure,String msg)
	{
		String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
		String result = String.format("%s-Error-%s-%s", timeStamp,procedure,msg);
		try {
			_writer.write(result);
			_writer.write("\n");
			_writer.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
